package com.aier.controller.inventory;


import com.aier.bean.inventory.Bean;
import com.aier.bean.DemoDataListener;
import com.aier.bean.inventory.InventoryBean;
import com.aier.bean.common.CommonResult;
import com.aier.service.inventory.InventoryService;
import com.alibaba.excel.EasyExcel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 库存controller
 * **/
@Controller
public class InventoryController {

    @Resource
    private InventoryService inventoryService;

    @RequestMapping("/model_name_list")
    @ResponseBody
    public CommonResult getAllModeName(){
        return inventoryService.getAllModeName();
    }

    @RequestMapping("/get_all_salesperson")
    @ResponseBody
    public CommonResult getAllSalespersonName(){
        return inventoryService.getAllSalespersonName();
    }

    @RequestMapping("/enter_inventory")
    @ResponseBody
    public CommonResult saveInventory(@RequestBody InventoryBean inventoryBean){
        /** 先判断商品型号是否存在，存在则插入失败 **/
        inventoryService.inventoryIsExist(inventoryBean.getModelName());
        return inventoryService.saveInventory(inventoryBean);
    }

    @RequestMapping("insertSku")
    @ResponseBody
    public CommonResult insertSku(String path){
        EasyExcel.read(path, Bean.class, new DemoDataListener()).sheet().doRead();
        return CommonResult.success();
    }

}
